<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/static/layui/css/layui.css"/>
    <script src="/static/js/jquery.js"></script>
    <script src="/static/layui/layui.js"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
       .project{
           letter-spacing: 10px;
           font-size: 50px;
           margin-left: 30px;
           margin-top: 20px;
       }
       .layui-form{
           margin-top: 50px;
       }
    </style>
</head>
<body>


<h1 class="project">Flavor 数</h1>
<form class="layui-form" action="" id="searchForm">
    <div class="layui-form-item">
        <br>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="phone" id="phone"  class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <a  onclick="doSearch1()" class="layui-btn layui-btn-radius" >搜索</a>
            <button type="reset" class="layui-btn  layui-btn-radius ">重置</button>
        </div>
    </div>
</form>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm" lay-event="add">创建</button>
        <button class="layui-btn layui-btn-danger" lay-event="delete">删除</button>
    </div>
</script>
<div style="max-width: 728px;">
  <table class="layui-hide" id="test-dropdown-table" lay-filter="test-dropdown-table"></table>
</div>
<script type="text/html" id="test-dropdown-toolbar-barDemo">
  <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="start">启动</a>
  <a class="layui-btn layui-btn-xs" lay-event="more">更多 <i class="layui-icon layui-icon-down"></i></a>
</script>

<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
layui.use(['dropdown', 'util', 'layer', 'table'], function(){
  var dropdown = layui.dropdown
  ,util = layui.util
  ,layer = layui.layer
  ,table = layui.table
  ,$ = layui.jquery;
    // dropdown 在表格中的应用
  table.render({
    elem: '#test-dropdown-table'
    ,url: '/wyh0282/flavorJson'/*tpa=https://www.layuiweb.com/test/table/demo5.json*/
    ,title: '用户数据表'
    ,toolbar: '#toolbarDemo'
    ,height:400
    ,width:1250
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
                    /*  ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}*/
                    ,{field:'name', title:'flavor名称', width:190}
                    ,{field:'vcpus', title:'VCPU 数量 ', width:150}
                    ,{field:'ram', title:'内存', width:100}
                    ,{field:'disk', title:'根磁盘',width:100}
                    ,{field:'OS-FLV-EXT-DATA:ephemeral', title:'临时磁盘', width:100}
                    ,{field:'OS-FLV-EXT-DATA:ephemeral', title:'交换磁盘', width:100}
                    ,{field:'rxtx_factor', title:'RT/TX因子', width:100}
                    ,{field:'id', title:'标识', width:100}
                    ,{field:'os-flavor-access:is_public', title:'共有', width:100}
                    ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo', width:150}
    ]]
    ,limits: [3]
    ,page: true
  });
  //工具栏事件
        table.on('toolbar(test-dropdown-table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
                case 'add':
                    parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'创建映像'
                        ,content:'/wyh0282/imagesAdd'
                        ,area:['1000px','600px']
                        ,btn:'关闭全部'
                        ,btnAlign:'c'
                        ,yes:function () {
                            parent.layer.closeAll();
                        }
                        , end:function () {
                            location.reload(); //踩了好多坑才弄出来的，最后加载当前页面
                        }

                    });
                    break;
            };
        });

  //行工具事件
  table.on('tool(test-dropdown-table)', function(obj){
    var server_id = obj.data.id; //获得当前行数据
    var that = this
    if(obj.event === 'start'){
       $.get("/wyh0282/imagesStart",{id:server_id},function (respData) {
           if(respData.code==1){
               layer.msg("启动映像成功！");
               window.parent.location.reload();
           }else {
               layer.msg("启动映像失败！");

           }
       });
    }else if(obj.event === 'more'){
      //更多下拉菜单
      dropdown.render({
        elem: that
        ,show: true //外部事件触发即显示
        ,data: [{
           title: '修改访问权限'
          ,id: 'upImage'
          },{
          title: '更新元数据'
          ,id: '修改元数据'
        }, {
          title: '删除flavor'
          ,id: 'delete'
        }]
        ,click: function(data, othis){
          //根据 id 做出不同操作
          if(data.id === 'del'){

          } else if(data.id === 'upImage'){
              parent.layer.open({
                        type: 2
                        ,offset:'auto'
                        ,title:'上传映像'
                        ,content:'/wyh0282/imagesUp?image_id='+server_id
                        ,area:['1000px','600px']
                        ,btn:'关闭全部'
                        ,btnAlign:'c'
                        ,yes:function () {
                            parent.layer.closeAll();
                        }
                        , end:function () {
                            location.reload(); //踩了好多坑才弄出来的，最后加载当前页面
                        }

                    });
          }else if(data.id === 'delete'){
              layer.confirm('亲，真的删除这个映像吗？', function(index) {
                  obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                  layer.close(index);
                  //向服务端发送删除指令
                  $.get("/wyh0282/imagesDelete", {image_id: server_id}, function (respData) {
                      //alert(respData);
                      if (respData.code == 1) {
                          layer.msg("删除映像成功！");
                          window.parent.location.reload();
                      } else {
                          layer.msg("删除映像失败！");
                      }
                  });

              })
          } else {
            layer.msg('得到表格下拉菜单 id：'+ data.id);
          }
        }
        ,align: 'right' //右对齐弹出（v2.6.8 新增）
        ,style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
      });
    }
  });
});
</script>


</body>
</html>